[Mobile Payments] Prevent sleep during Card Reader software updates #14021
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR disables sleep on a user's device for the duration of any Card Reader software updates.
Steps to reproduce
Terminal.shared.simulatorConfiguration.availableReaderUpdate = .required
in theStripeCardReaderService
StripeCardReaderService.reader(_:didStartInstallingUpdate:cancelable:)
andStripeCardReaderService.reader(_:didFinishInstallingUpdate:error:)
Testing information
The shortest auto-lock is 30s – this is longer than it takes to complete a (simulated) reader update, but using a timer to trigger the connection allowed me to check that it doesn't autolock during a (real) update, and does after the update completes.
I added
DispatchQueue.main.asyncAfter(deadline: .now() + 22)
in a Task inCardReaderConnectionController.onFoundReader()
. I used 22 seconds to give it time to connect and start the update before the sleep timer kicks in – we don't disable device sleep until the install actually starts.It's important to note that the device won't sleep while connected to the Xcode debugger regardless of what you do, so timer-based testing should be done without a connection to Xcode. This means you need a reader which has a pending update to test in this way, as the Stripe simulated readers only work when you're connected to Xcode.
If you have such a reader, be sure to cancel any updates before they complete!
Also it's best to turn of
Settings > Face ID > Attention Aware Features
to ensure you're not keeping your phone awake by looking at it.StripeCardReaderService isn't unit tested due to the difficulties presented by faking the Stripe SDK.
Screenshots
Before
before.mp4
After
after.mp4
Note that after the reader update is cancelled, the phone is allowed to go to sleep again, so 30s after the cancellation, the display goes to sleep in this second video.
RELEASE-NOTES.txt
if necessary.Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: